
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _utils = require('../utils');

const _router = require('../utils/router');

const _relation = require('../mixins/relation');

const _info = _interopRequireDefault(require('../info'));

const _icon = _interopRequireDefault(require('../icon'));

const _createNamespace = (0, _utils.createNamespace)('goods-action-icon');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

const _default = createComponent({
  mixins: [(0, _relation.ChildrenMixin)('vanGoodsAction')],
  props: (0, _extends2.default)({}, _router.routeProps, {
    dot: Boolean,
    text: String,
    icon: String,
    color: String,
    info: [Number, String],
    badge: [Number, String],
    iconClass: null,
  }),
  methods: {
    onClick: function onClick(event) {
      this.$emit('click', event);
      (0, _router.route)(this.$router, this);
    },
    genIcon: function genIcon() {
      const h = this.$createElement;
      const slot = this.slots('icon');
      const info = (0, _utils.isDef)(this.badge) ? this.badge : this.info;

      if (slot) {
        return h('div', {
          class: bem('icon'),
        }, [slot, h(_info.default, {
          attrs: {
            dot: this.dot,
            info,
          },
        })]);
      }

      return h(_icon.default, {
        class: [bem('icon'), this.iconClass],
        attrs: {
          tag: 'div',
          dot: this.dot,
          info,
          name: this.icon,
          color: this.color,
        },
      });
    },
  },
  render: function render() {
    const h = arguments[0];
    return h('div', {
      attrs: {
        role: 'button',
        tabindex: '0',
      },
      class: bem(),
      on: {
        click: this.onClick,
      },
    }, [this.genIcon(), this.slots() || this.text]);
  },
});

exports.default = _default;
